package com.onlineMIS.ORM.DAO.headQ.qxbabydb;

import java.util.List;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import com.onlineMIS.ORM.DAO.BaseDAO2;
import com.onlineMIS.ORM.entity.headQ.qxbabydb.ProductBarcodePic2;
import com.onlineMIS.common.Common_util;
import com.onlineMIS.filter.SystemParm;

@Repository
public class ProductBarcodePicDaoImpl2 extends BaseDAO2<ProductBarcodePic2> {

	
	/**
	 * 根据pbId查询条码图片路径
	 * 
	 * 禧乐仓用条码获取图片
	 * @param pbId
	 * @return
	 */
//	public String getPicPath(int pbId,int type) {
//		DetachedCriteria pCriteria = DetachedCriteria.forClass(ProductBarcodePic2.class);
//		
//		pCriteria.add(Restrictions.eq("pbId", pbId));
//		
//		if (type != Common_util.ALL_RECORD)
//		     pCriteria.add(Restrictions.eq("type", type));
//		
//		List<ProductBarcodePic2> list = this.getByCritera(pCriteria, true);
//		if (list.size() != 0) {
//			return list.get(0).getPicPath();
//		}else {
//			return null;
//		}
//	}
	
	
	
	/**
	 * 根据条码查询图片
	 * @param pbId
	 * @return
	 */
	public String getPathByBarcode(String barcode,int type) {
			
		DetachedCriteria pCriteria = DetachedCriteria.forClass(ProductBarcodePic2.class);
		
		pCriteria.add(Restrictions.eq("barcode", barcode));
		if (type != Common_util.ALL_RECORD)
		     pCriteria.add(Restrictions.eq("type", type));
				
		List<ProductBarcodePic2> list = this.getByCritera(pCriteria, true);
		if (list.size() != 0) {			
			return SystemParm.getQxPicURLHead() + list.get(0).getPicPath();
		}else {
			return null;
		}
	}



	/**
	 * 根据条码查询图片
	 * @param pbId
	 * @return
	 */
	public String getURLPathByBarcode(String barcode,int type) {
			
		DetachedCriteria pCriteria = DetachedCriteria.forClass(ProductBarcodePic2.class);
		
		pCriteria.add(Restrictions.eq("barcode", barcode));
		if (type != Common_util.ALL_RECORD)
		     pCriteria.add(Restrictions.eq("type", type));
				
		List<ProductBarcodePic2> list = this.getByCritera(pCriteria, true);
		if (list.size() != 0) {			
			return SystemParm.getQxPicURLHead() + list.get(0).getPicPath();
		}else {
			return null;
		}
	}
	
}
